﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DeepTime.DataSources.DL;
using Microsoft.WindowsAzure.StorageClient;
using Microsoft.WindowsAzure;

namespace DeepTime.DL.DataSources
{
    public class CollageImageProcessorQueueDataSource: IDataSource<CloudQueueMessage>
    {
        #region Class Members

        private CloudQueueClient _QueueClient;
        private CloudQueue _Queue;

        #endregion Class Members

        #region Constructors

        public CollageImageProcessorQueueDataSource()
        {
            CloudStorageAccount StorageAccount = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");
            _QueueClient = StorageAccount.CreateCloudQueueClient();
            _Queue = _QueueClient.GetQueueReference("collageimages");

            //
            // This should be optimized at a later stage since you don't need to check the table exists EVERY time an instance of the data source is created.
            //
            _Queue.CreateIfNotExist();
        }

        #endregion Constructors

        #region Methods

        public IEnumerable<CloudQueueMessage> Select()
        {
            throw new NotImplementedException();
        }

        public CloudQueueMessage SelectFirst()
        {
            return _Queue.GetMessage(TimeSpan.FromHours(1));
        }

        public void Delete(CloudQueueMessage DataModelToDelete)
        {
            _Queue.DeleteMessage(DataModelToDelete);
        }

        public void Insert(CloudQueueMessage DataModel)
        {
            _Queue.AddMessage(DataModel);
        }

        public void Update(CloudQueueMessage DataModel)
        {
            throw new NotImplementedException();
        }

        #endregion Methods
    }
}
